package common

import (
	"gitlab.local/golibrary/utils"
	"os/exec"
	"path/filepath"
	"strings"
)

// IsRunning check if the process running
func IsRunning(name string) bool {
	if filepath.IsAbs(name) {
		if utils.Exists(name) {
			f, _ := exec.Command(name, "status").Output()
			s := strings.TrimSpace(string(f))
			if s != "" && strings.Contains(s, "running") {
				return true
			}
			return false
		}
		name = filepath.Base(name)
	}
	b, _ := exec.Command("pidof", name).Output()
	return len(b) > 0
}
